import { 
  GET_VALIDATE_PICTURE, 
  GET_VALIDATE_PICTURE_FAIL,
  SET_VALIDATE_PICTURE, 
  SET_ACCOUNT,
  SET_PASS_WORD,
  SET_VALIDATE_CODE,
  LOGIN, 
  LOGIN_SUCCESS,
  LOGIN_FAIL,
} from '@/actions/login'

const initState = {
  validatePictureData: '',// 验证码图片 base64
  spinningValiCoder: false,
  account: '',// 账号
  passWord: '',// 密码
  validateCode: '',// 验证码
  loginButtonLoading: false, // 登录按钮加载状态
}

const loginReducer = (state = initState, action) => {
  switch (action.type) {
    case GET_VALIDATE_PICTURE:
      return { ...state, spinningValiCoder: true }
      break;

    case GET_VALIDATE_PICTURE_FAIL:
      return { ...state, spinningValiCoder: false }
      break;

    case SET_VALIDATE_PICTURE:
      return { ...state, validatePictureData: action.validatePictureData, spinningValiCoder: false }
      break;

    case SET_ACCOUNT:
      return { ...state, account: action.account }
      break;

    case SET_PASS_WORD:
      return { ...state, passWord: action.passWord }
      break;

    case SET_VALIDATE_CODE:
      return { ...state, validateCode: action.validateCode }
      break;

    case LOGIN:
      return { ...state, loginButtonLoading: true }
      break;

    case LOGIN_SUCCESS:
      return { ...state, loginButtonLoading: false, account: '', passWord: '', validateCode: '' }
      break;

    case LOGIN_FAIL:
      return { ...state, loginButtonLoading: false, validateCode: '' }
      break;
  
    default:
      return state
      break;
  }
}

export default loginReducer